import { Container } from "pixi.js";
import { MyContainer } from "@/containers/MyContainer.js";
import { ImageManager } from "@/managers/ImageManager.js";

export class Scene_Base extends Container {
    constructor() {
        super();
        this.active = false;
        this.fadeDirect = 0;
        this.fadeDuration = 0;
        this.interactive = false;
        this.windowLayer=null;
    }

    create() {}
    isActive() { return this.active; }
    isReady() { return ImageManager.isReady(); }
    start() { this.active = true; }
    isBusy() { return this.fadeDuration > 0; }
    stop() { this.active = false; }
    terminate() { this.destroy({ children: true }); }
    fadeOutAll() { }
    fadeSpeed() { return 24; }
    slowFadeSpeed() { return this.fadeSpeed() * 2; }
    //addWindow(windowBase){this.addChild(windowBase)};

    update() {
        this.updateFade();
        this.updateChildren();
    }

    startFadeIn(duration) {
        this.fadeDuration = duration;
        this.alpha = 0;
        this.fadeDirect = 1 / this.fadeDuration;
    }

    startFadeOut(duration) {
        this.fadeDuration = duration;
        this.fadeDirect = - this.alpha / this.fadeDuration;
    }

    updateFade() {
        if (this.fadeDuration > 0) {
            let alpha = this.alpha + this.fadeDirect;
            if (alpha < 0) {
                alpha = 0;
                this.fadeDuration = 0;
            } else if (alpha > 1) {
                alpha = 1;
                this.fadeDuration = 0;
            }

            this.alpha = alpha;
        }
    }

    updateChildren() {
        for (let child of this.children) {
            child.update?.();
        }
    }

    addWindow(windowBase){
        // if(!this.windowLayer){
        //     this.windowLayer=new MyContainer();
        //     this.addChild(this.windowLayer);
        // }
        // this.windowLayer.addChild(windowBase);
        this.addChild(windowBase);
    }
}